﻿using System;
using ZX.BLL.Extend;
using ZX.DAL.DBExtend;
using System.Data;
using System.Data.SqlClient;

namespace ZX.BLL.EHR.Time
{
    public class Ehr_Scheduling : BaseBussnies
    {

        public Ehr_Scheduling()
        {
        }

        /// <summary>
        /// 计算请假天数与小时数
        /// </summary>
        /// <param name="EmployeeID">员工ID</param>
        /// <param name="FrmDatetime">统计开始日期</param>
        /// <param name="TODatetime">统计结束日期</param>
        /// <param name="IsIncludeHoliday">请假时长是否包含节假日，1-包含，0-不包含</param>
        /// <param name="Msg">提示信息，如无排班信息</param>
        /// <returns>-请假总小时数</returns>
        public float HRGetEmpTotalVation(Guid EmployeeID, DateTime FrmDatetime, DateTime TODatetime, int IsIncludeHoliday,out float LeaveDay, out string Msg)
        {
            float result = 0.0f;
            try
            {

                Msg = "";
                LeaveDay = 0.0f;
                DbSql dbsql = new DbSql();
                IDataParameter[] parameters = new SqlParameter[6];
                parameters[0] = new SqlParameter("@EmployeeID", SqlDbType.UniqueIdentifier);
                parameters[0].Value = EmployeeID;
                parameters[1] = new SqlParameter("@FrmDatetime", SqlDbType.DateTime);
                parameters[1].Value = FrmDatetime;
                parameters[2] = new SqlParameter("@TODatetime", SqlDbType.DateTime);
                parameters[2].Value = TODatetime;
                parameters[3] = new SqlParameter("@IsIncludeHoliday", SqlDbType.Int);
                parameters[3].Value = IsIncludeHoliday;
                parameters[4] = new SqlParameter("@LeaveTime", SqlDbType.Float);
                parameters[4].Value = result;
                parameters[4].Direction = ParameterDirection.Output;
                parameters[5] = new SqlParameter("@Msg", SqlDbType.VarChar, 100);
                parameters[5].Value = Msg;
                parameters[5].Direction = ParameterDirection.Output;
                result=dbsql.RunEhrProcedure("sp_HR_GetEmpTotalVation", parameters, out Msg);
                if (result != 0.0f) { LeaveDay = result / 8.0f;}//计算多小天。
             
            }
            catch (Exception ex)
            {

                throw ex;
            }
            return result;
        }


        /// <summary>
        /// 计算请假天数与小时数
        /// </summary>
        /// <param name="EmployeeID">员工ID</param>
        /// <param name="FrmDatetime">统计开始日期</param>
        /// <param name="TODatetime">统计结束日期</param>
        /// <param name="IsIncludeHoliday">请假时长是否包含节假日，1-包含，0-不包含</param>
        /// <param name="Msg">提示信息，如无排班信息</param>
        /// <returns>-请假总小时数</returns>
        public float HRGetEmpTotalVation(Guid EmployeeID, DateTime FrmDatetime, DateTime TODatetime, int IsIncludeHoliday, out float LeaveDay, out string Msg,string VName)
        {
            float result = 0.0f;
            try
            {

                Msg = "";
                LeaveDay = 0.0f;
                DbSql dbsql = new DbSql();
                IDataParameter[] parameters = new SqlParameter[7];
                parameters[0] = new SqlParameter("@EmployeeID", SqlDbType.UniqueIdentifier);
                parameters[0].Value = EmployeeID;
                parameters[1] = new SqlParameter("@FrmDatetime", SqlDbType.DateTime);
                parameters[1].Value = FrmDatetime;
                parameters[2] = new SqlParameter("@TODatetime", SqlDbType.DateTime);
                parameters[2].Value = TODatetime;
                parameters[3] = new SqlParameter("@IsIncludeHoliday", SqlDbType.Int);
                parameters[3].Value = IsIncludeHoliday;
                parameters[4] = new SqlParameter("@LeaveTime", SqlDbType.Float);
                parameters[4].Value = result;
                parameters[4].Direction = ParameterDirection.Output;
                parameters[5] = new SqlParameter("@Msg", SqlDbType.VarChar, 100);
                parameters[5].Value = Msg;
                parameters[5].Direction = ParameterDirection.Output;
                parameters[6] = new SqlParameter("@Vation", SqlDbType.VarChar, 100);
                parameters[6].Value = VName;

                result = dbsql.RunEhrProcedure("sp_HR_GetEmpTotalVation", parameters, out Msg);
                if (result != 0.0f) { LeaveDay = result / 8.0f; }//计算多小天。

            }
            catch (Exception ex)
            {

                throw ex;
            }
            return result;
        }
    }
}
